<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$merchid=intval($_RQ['id'])?:intval($_RQ['merchid']);
	if($merchid){
		$_SESSION['merchid']=$merchid;
	}else{
		$merchid=$_SESSION['merchid'];
	}
	$myshop=pdo_get('jy_merch_user',array('id'=>$merchid));	
	$return['myshop']=$myshop;
	$return['pluginset']=$this->plugin_setting('merch'.$merchid);
	if(!$return['pluginset']){
		$footernav = array(
			array('title'=>'首页','icon'=>'icon-shouye','color'=>'#cc99ff','action'=>'jy_mfuwu/app.index/','image'=>'../addons/jy_weishop/resource/images/jy_weishoparticle.png'),
			array('title'=>'本店服务','icon'=>'icon-all','color'=>'#66cc99','action'=>'jy_mfuwu/app.shop.groups/','image'=>'../addons/jy_weishop/resource/images/jy_fenleimsg.png'),
			array('title'=>'本店订单','icon'=>'icon-manageorder','color'=>'#66cc66','action'=>'jy_mfuwu/app.order.list/','image'=>'../addons/jy_weishop/resource/images/jy_fenleimsg.png'),
			array('title'=>'我的','icon'=>'icon-wo1','color'=>'#FF83FA','action'=>'jy_mfuwu/app.member.index/','image'=>'../addons/jy_weishop/resource/images/jy_fenleimsg.png'),
		);
		$hdps = array(
				array('title'=>'家电维修','icon'=>'icon-shouye','picurl'=>'../addons/jy_mfuwu/resource/images/hdp01.jpg'),
				array('title'=>'门窗维修','icon'=>'icon-viewlist','picurl'=>'../addons/jy_mfuwu/resource/images/hdp02.jpg'),
		);
		$cube =array(
			array('title'=>'首页','image'=>'../addons/jy_mfuwu/resource/images/cube01.jpg','action'=>'index/'),
			array('title'=>'全部','image'=>'../addons/jy_mfuwu/resource/images/cube02.jpg','action'=>'index/'),
		);
		$return['pluginset']['footernav']=$footernav;
		$return['pluginset']['hdps']=$hdps;
		$return['pluginset']['cube']=$cube;
		$return['pluginset']['keyword']=$return['pluginset']['keyword']?:'门窗维修;家电维修;空调清洁;抽油烟机;洗卫保修';
	}
	$return['welcomehdps']=$return['pluginset']['welcomehdps'];
	if(count($return['welcomehdps'])>0 && $return['pluginset']['iswelcome']==1){
		$return['iswelcome']=$this->session('iswelcome')?0:1;
		if($return['iswelcome']){
			$this->session('iswelcome',1);
		}
	}
	$return['pluginset']['keyword']=str_array($return['pluginset']['keyword']);
	$return['member']=cfc('core')->get_member($_SESSION['uid']);
	$return['member']['barcode']='0-';
	$return['member']['barcode'].=$_SESSION['uid']+10000000000000000;
	$pindex = max(1, intval($post['page']));
	$psize = 30;
	$total='';
	$fuwucate = pdo_getslice('jy_weishop_goods_group',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1,'is_fuwu'=>1,'mid'=>$myshop['mid'],'onepluginname'=>'jy_mfuwu'),array($pindex,$psize),$total,array('id','title','image'),'','id desc');
	$return['fuwucate']=$fuwucate;
	$shopset=$return['setting']=$return['pluginset'];
	$sale_luck=plugin('jy_weishop')->plugin_setting('sale_luck');
	if($sale_luck['isopen']==1){
			if(isset($_RQ['luckkey'])){
				$return['sale_luck']=model('jy_weishop/activity/sales')->jieluck($_RQ['luckkey']);
			}else{
				$return['sale_luck']=model('jy_weishop/activity/sales')->getluck();
			}
	}
	if(!$return['sale_luck']){
			$isshow_sale_offer=$this->session('isshow_sale_offer');
			if(!$isshow_sale_offer){
				$return['sale_offer']=model('jy_weishop/activity/sales')->getoffer();
			}
			if(!$return['sale_offer']){
				if($shopset['no_ordermodal']!=1){
					$return['orderlist']=pdo_getslice('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'status'=>0),array($pindex,$psize),$total,'','','createtime desc');
					foreach($return['orderlist'] as &$ov){
						$ordergoods=pdo_get('jy_weishop_order_goods',array('orderid'=>$ov['id'],'uniacid'=>$_SESSION['uniacid']),array('goodsid','optionid','price','total','goodssn','productsn'));
						$goodsinfo=pdo_get('jy_weishop_goods',array('id'=>$ordergoods['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','image','title','merchid'));
						$ov['goods']=array_merge($ordergoods,$goodsinfo);
						$ov['createtime']=date('Y/m/d H:i:s',$ov['createtime']);
						$ov['total']=pdo_getsum('jy_weishop_order_goods',array('orderid'=>$ov['id'],'uniacid'=>$_SESSION['uniacid']),'total');
					}
					$return['allprice']=pdo_getsum('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'deleted'=>0,'status'=>0),'price');
				}
				if(empty($return['orderlist'])){
					$return['coupon_wait']=model('jy_weishop/task')->pop_coupon_wait();
					$return['coupon_wait']=$return['coupon_wait']?$return['coupon_wait'][0]:false;
					if(!$return['coupon_wait']){
						$return['coupon_hd']=model('jy_weishop/task')->pop_coupon_hd();
						if(!$return['coupon_hd']){
							$return['game_wait']=model('jy_weishop/task')->pop_game();
						}
					}
				}
			}else{
					$this->session('isshow_sale_offer',1);
			}
	}
	$sharelink='jy_mfuwu/app.index//fromuser='.$_SESSION['uid'].'&merchid='.$_SESSION['merchid'];
	$return['sharedata']=array(
			'title'=>$setting['share_title']?$setting['share_title']:'首页-在线维修',
			'desc'=>$setting['share_desc']?$setting['share_desc']:'在线维修，一个属于自己的在线维修系统！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>ATTACHMENT_URL.$setting['share_image']
	);
	$return['list']=array();
	$return['pcd']=array('city'=>'深圳');
	$return['params']=array('pid'=>0,'isrecommand'=>1);
	foreach($return['setting']['baoxiu_list'] as &$bv){
		$bv['img']=tomedia($bv['img']);
	}
	foreach($return['setting']['qingxi_list'] as &$bv){
		$bv['img']=tomedia($bv['img']);
	}
	foreach($return['setting']['taocan_list'] as &$bv){
		$bv['img']=tomedia($bv['img']);
	}
	set_html('title',$return['pluginset']['title']?:'在线维修');
	exi($return);
}
if($_RQ['op']=='out_time'){
	$store_id=intval($_RQ['store_id'])?:$this->session('store_id');
	$merch_id=intval($_RQ['merch_id']);
	$citypeisong=plugin('jy_weishop')->plugin_setting('citypeisong');
	$post['set_timebox']=$citypeisong['set_timebox'];
	$post['peisong_timebox']=$citypeisong['peisong_timebox'];
	$post['out_pay']=$_RQ['out_pay'];
	$out_time = model('jy_mfuwu/model')->out_times($store_id,$post);
	$timestamp = TIMESTAMP + 60 * 30;
	$data = model('jy_weishop/store')->array_order($timestamp, $out_time['timestamp']);
	$predict_index = array_search($data, $out_time['timestamp']);
	$predict_day = $out_time['days'][0];
	$predict_time = $out_time['times'][$predict_index]['start'].'~'.$out_time['times'][$predict_index]['end'];
	$text_time = "尽快上门";
	$return['timestamp']=$timestamp;
	$return['predict_time']=$predict_time;
	$return['out_time']=$out_time;
	exi($return);
}
?>